//
//  AnimationView2.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI

struct AnimationView2: View {
  @State private var circleColorChange = false
  @State private var heartColorChange = false
  @State private var heartSizeChange = false
  
  var body: some View {
    Text("父控件使用animation").font(.title)
    // 方式2: animation直接写在父控件上
    ZStack {
      Circle()
        .frame(width: 200, height: 200)
        .foregroundStyle(circleColorChange ? Color(.systemGray5) : .red)
      
      Image(systemName: "heart.fill")
        .foregroundStyle(heartColorChange ? .red : .white)
        .font(.system(size: 100))
        .scaleEffect(heartSizeChange ? 1.0 : 0.5)
    }
    
    .animation(.spring(response: 0.53, dampingFraction: 0.53, blendDuration: 0.53), value: circleColorChange)
    //      .animation(.default, value: heartSizeChange)
    
    .onTapGesture {
      circleColorChange.toggle()
      heartSizeChange.toggle()
      heartColorChange.toggle()
    }
  }
}

#Preview {
  AnimationView2()
}
